package com.bh.ly.oa.adapter;

import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bh.ly.oa.R;

public class NoticeListAdapter extends BaseAdapter {

	public List<JSONObject> getArray() {
		return array;
	}

	public void setArray(List<JSONObject> array) {
		this.array = array;
	}

	List<JSONObject> array = null;
	Context context = null;

	public NoticeListAdapter(Context context) {
		this.context = context;
		// this.array = HttpClent.getNoticeJsonData(((NoticeActiivity)context).getparamMap());
	}

	@Override
	public int getCount() {
		return array.size();
	}

	@Override
	public Object getItem(int position) {
		return array.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		NoticeItem noticeItem = null;
		if (convertView == null) {
			noticeItem = new NoticeItem();
			convertView = LayoutInflater.from(context).inflate(R.layout.notice_item, null);
		} else {
			noticeItem = (NoticeItem) convertView.getTag();
		}

		JSONObject jsonObject = (JSONObject) array.get(position);
		noticeItem.jsonobject = jsonObject;
		initView(position, convertView, noticeItem);
		try {
			noticeItem.title.setText(jsonObject.getString("subject"));

		} catch (JSONException e) {
			e.printStackTrace();
		}
		return convertView;
	}

	private void initView(int position, View convertView, NoticeItem noticeItem) {
		noticeItem.title = (TextView) convertView.findViewById(R.id.notice_title);
		convertView.setTag(noticeItem);
	}

	class NoticeItem {
		TextView title;
		JSONObject jsonobject;
	}

}
